<?php
namespace app\index\model;
use think\Model;

class Area extends Model
{
	// 获取省份
	public function getProvince()
	{
		$data = [
			'level' => 1,
			'pid' => 0,
		];

		return $this->where($data)->select();
	}

	// 获取城市
	public function getCity()
	{
		$data = [
			'level' => 2,
			'pid' => ['neq',0],
		];

		return $this->where($data)->select();
	}

	// 根据省份获取城市
	public function getCityById($pid)
	{
		$data = [
			'level' => 2,
			'pid' => $pid,
		];

		return $this->where($data)->select();
	}

	// 根据id获取省市
	public function getAddressById($id)
	{
		return $this->where('id',$id)->value('name');
	}
}